const Vue = require('vue');
const server = require('express')();

//express响应
server.get('/',(req,res)=>{
  
  //第 1 步：创建一个 Vue 实例
  const app = new Vue({
    template:`<div>${req.url}</div>`
  })

  // 第 2 步：创建一个 renderer
  const renderer = require('vue-server-renderer').createRenderer(); 

  renderer.renderToString(app).then(html=>{
    // console.log(html)
    res.send(`
      <!DOCTYPE html>
      <html lang="en">
      <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
      </head>
      <body>
        ${html}
      </body>
      </html>
    `)
  }).catch(err=>{
    console.log(err)
  })

})

server.listen(3001)